/**
 * User: anpengtao
 * Date: 16-8-18
 * Time: 上午9:04
 * 土地拓展备注查询
 */

define("require dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/_base/fx dojo/fx/easing ../../util/ajaxUtil dojo/dom dojo/dom-attr dojo/dom-class dojo/dom-style dojo/dom-construct dojo/on dojo/query dojo/topic ../BaseWidget esri/symbols/SimpleFillSymbol esri/symbols/SimpleLineSymbol esri/graphic esri/layers/GraphicsLayer esri/Color esri/SpatialReference esri/tasks/query esri/layers/FeatureLayer esri/geometry/Point gistech/widgets/QueryTableList/QueryTableList gistech/util/infoUtil dijit/layout/ContentPane dojo/text!./templates/Template.html".split(" "),
    function (require, declare, lang, array, baseFx,easing,ajaxUtil, dom, domAttr, domClass, domStyle,domConstruct, on, query, topic, BaseWidget,SimpleFillSymbol,SimpleLineSymbol,Graphic,GraphicsLayer,Color,SpatialReference,Tquery,FeatureLayer,Point,QueryTableList,infoUtil,ContentPane,template) {
        return declare([BaseWidget], {
            templateString: template,
            map: null,
            rightTab:null,
            ismove:false,//组件位置移动判断
            grouplist:null,
            landExpandlayer:null,
            landareaGraphicLayer:null,
            landResources:null,
            constructor: function (args) {
                this.map = args.map;
                this.rightTab = args.rightTab==undefined?null:args.rightTab;
                this.advQueryTableColumnsData=null;
                this.LandMapLevel=Global.widgets["mapWidget"].map.getLevel();
            	this.advQueryTableData=null;
            	
            	this.advQueryTableSortName='XH';
            	this.advQueryTableSortOrder='desc';
            },

            postCreate: function () {
            	this.inherited(arguments);
            	on(this.closebtn2,"click",lang.hitch(this,this.closeDialog));
            	topic.subscribe("queryBlockByObjectid",lang.hitch(this,this.locationById));
            	
            },
            startup: function () {
                this.inherited(arguments);
                this.init();
            },
            init:function(){
            	this._queryNoCheck();
            },
            locationById:function(e){
            	this.landExpandlayer=this.map.getLayer("LandFeatureLayerEdit");
            	this.landExpandlayer.refresh();
            	var index=layer.load(1);
            	var query=new Tquery();
            	query.where = "OBJECTID = '" + e.objectId + "'";
            	this.landExpandlayer.selectFeatures(query,FeatureLayer.SELECTION_NEW,lang.hitch(this,function(results){
            		var line1=new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,255,255,1]), 3);
					var symbol=new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,line1,new dojo.Color([255,0,125,1]));
					results[0].setSymbol(symbol);
            		this.map.centerAndZoom(results[0].geometry.getCentroid(),this.LandMapLevel+5);
            		layer.close(index);
            	}))
            },
            _LandTypeColumnData:function(){
    			var arr=[
                       {field:'OBJECTID',title:'地块id',width:30,align:'center',sortable:false,visible:false},
      				   {field:'LANDBH',title:'地块编号',width:30,align:'center',sortable:true},
      				   {field:'XH',title:'地块序号',width:30,align:'center',sortable:true,visible:false}, 
                       {field:'LANDNAME',title:'地块名称',width:40,align:'center'},
                       {field:'PROJECTTYPE',title:'项目属性', width:30,align:'center'},
                       {field:'EXPENDTYPE',title:'拓展类型',width:30,align:'center'},
                       {field:'TYPE',title:'项目类型',width:30,align:'center',visible:false},
                       {field:'TOTALAREA',title:'总面积',width:30,align:'center',visible:false},
    			       {field:'NETLANDAREA',title:'可用面积',width:30,align:'center',visible:false}]
    			this.advQueryTableColumnsData=arr;
    		},
            _queryNoCheck:function(){
            	var arr=[];
            	this.landExpandlayer=this.map.getLayer("LandFeatureLayerEdit");
            	var query=new Tquery();
            	if(ioc.map.userInfoData.isManager==true){
            		query.where ="1=1";
            	}else{
            		var managerUsers = ioc.map.menagerUsers.split(",");
            		managerUsers=skipEmptyElementForArray(managerUsers);
    				var filter =" in (";
    				var layerDefinitions = [];//定义过滤条件  
    				for(var i=0;i<managerUsers.length;i++){
    					filter += "'"+managerUsers[i]+"'";  
    					if(i<managerUsers.length-1){
    						filter += ",";
    					}}
    				filter += ")";
            		query.where = "REGISTERUSER " + filter + ""; //userInfoData.USERID
            	}
            	if(!this.landExpandlayer){
            		layer.msg("请勾选拓展备注图层",{icon:2});
            		return false;
            	}else{
            		//将左侧组件展开
        			if(!Global.widgets.right.hasExpand){
        				Global.widgets.right.expandLeft();
        			}
            	}
            	this.landExpandlayer.selectFeatures(query,FeatureLayer.SELECTION_NEW,lang.hitch(this,function(results){
            		dojo.map(results,function(result){
            			var obj={};
            			obj["OBJECTID"]=result.attributes.OBJECTID;
            			obj["LANDBH"]=result.attributes.LANDBH;
            			obj["XH"]=result.attributes.XH;
            			obj["LANDNAME"]=result.attributes.LANDNAME;
            			obj["PROJECTTYPE"]=result.attributes.PROJECTTYPE;
            			obj["EXPENDTYPE"]=result.attributes.EXPENDTYPE;
            			obj["TOTALAREA"]=result.attributes.TOTALAREA;
            			obj["TYPE"]=result.attributes.TYPE;
            			obj["NETLANDAREA"]=result.attributes.NETLANDAREA;
            			arr.push(obj);
            		});
            		this._LandTypeColumnData();
            		this.advQueryTableData=arr;
            		this._createQueryTableListAndBind();
            	}));
            },
            _createQueryTableListAndBind:function(){
            	Global.currentUseFun="landExpandSearch";
            	var queryTableList=new QueryTableList({
            		"tableData":this.advQueryTableData,
					"columnsData":this.advQueryTableColumnsData,
					"sortName":this.advQueryTableSortName,
					"sortOrder":this.advQueryTableSortOrder
            	});
            	queryTableList.startup();
            	Global.widgets["tableList"]=queryTableList;
				if($(Global.widgets.right.domNode).children(".queryList").length!=0){
					$(Global.widgets.right.domNode).children(".queryList").remove();
				}
				$('.contentBody',this.domNode).empty();
				$('.contentBody',this.domNode).append(queryTableList.domNode);
				debugger
				var panel = new  ContentPane();
				$(panel.domNode).wrapInner(this.domNode);
				Global.widgets.right.removeAllTab();
				Global.widgets.right.addTab(panel);
            },
            closeDialog:function(){
     			this.inherited("closeDialog",arguments);
     			//this.rightTab.expandBtn.click();
     			if(Global.widgets.right.hasExpand){
    				Global.widgets.right.expandBtn.click();
    			}
     			this.destroy();
     		},
            destroy: function () {
                var widgets = this.widgets;
                for (var name in widgets) {
                    if (widgets[name]) {
                        widgets[name].destroy();
                    }
                }
                this.inherited(arguments);
            },
      
        });
    });



